package org.lgiavedoni.android.franq.command.general;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.lgiavedoni.android.franq.core.command.Command;
import org.lgiavedoni.android.franq.core.communication.imp.phone.CommunicationPhoneSpeech;
import org.lgiavedoni.android.franq.core.place.Place;
import org.lgiavedoni.android.franq.core.place.PlaceManager;
import org.lgiavedoni.android.franq.core.place.dao.PlaceDAO;
import org.lgiavedoni.android.franq.core.speak.CommonPhraseHelper;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;

public class SilenceCommand extends Command {

	private static final String OPTION_OFF = "off";

	@Override
	public void setOptions(Options options) {
		options.addOption(OPTION_OFF, false, "Disable the silence");
	}

	@Override
	public boolean execute(CommandLine cmd) throws Exception {
		Place currentPlace = PlaceManager.inst.getCurrentPlace();
		if (cmd.hasOption(OPTION_OFF)) {
			if (currentPlace != null) {
				currentPlace.setSpeakHere(true);
				PlaceDAO.inst.update(currentPlace);
			} else {
				CommunicationPhoneSpeech.inst.nowYouCanSpeakAgain();
			}
		} else {
			if (currentPlace != null) {
				currentPlace.setSpeakHere(false);
				PlaceDAO.inst.update(currentPlace);
			} else {
				CommunicationPhoneSpeech.inst.silencePlease();
			}
		}
		CommunicationService.inst.sendMessage(CommonPhraseHelper.DONE);
		return true;
	}

	@Override
	public String getCommandText() {
		return "shhh";
	}
}